package controller

import (
	"gitee.com/Frank098/devops-app-mgt/model"
	"gitee.com/Frank098/devops-app-mgt/service"
	"github.com/gin-gonic/gin"
)

var Node node

type node struct{}

// @Tags Nodes
// @Summary 获取单个节点信息
// @Accept json
// @Produce json
// @Param nodes_name query string true "nodes名称"
// @Success 200 {object} model.Result ""
// @Failure 400 {object} model.Result ""
// @Router /nodes/info [GET]
func (n *node) GetNodeInfo(ctx *gin.Context) {
	var params model.GetNodes
	if err := ctx.Bind(&params); err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	data, err := service.Node.GetNodeInfo(params.NodesName)
	if err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	SuccessResponse(ctx, &model.Result{
		Code: 200,
		Msg:  "Success",
		Data: data,
	})
}

// @Tags Nodes
// @Summary 获取所有节点信息
// @Accept json
// @Produce json
// @Success 200 {object} model.Result ""
// @Failure 400 {object} model.Result""
// @Router /nodes/all [GET]
func (n *node) GetNodeAll(ctx *gin.Context) {
	data, err := service.Node.GetNodeAll()
	if err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	SuccessResponse(ctx, &model.Result{
		Code: 200,
		Msg:  "Success",
		Data: data,
	})
}
